﻿namespace _04.CalcTriangleSurface
{
    using System;

    public enum TriangleInputType
    {
        SideC,
        Angle
    }

    public class Triangle
    {
        public Triangle(double side, double altitude)
        {
            this.Surface = (side * altitude) / 2;
        }

        public Triangle(double sideA, double sideB, double sideCOrAngle, TriangleInputType inputType)
        {
            switch (inputType)
            {
                case TriangleInputType.SideC:
                    double sideC = sideCOrAngle;
                    double p = ((sideA + sideB + sideC) / 2);
                    this.Surface = Math.Sqrt(p * (p - sideA) * (p - sideB) * (p - sideC));
                    break;
                case TriangleInputType.Angle:
                    double angleDegree = sideCOrAngle;
                    double sinAngle = Math.Sin((angleDegree * Math.PI) / 180);
                    this.Surface = (sideA * sideB * sinAngle) / 2;
                    break;
                default:
                    throw new NotImplementedException("Add as needed");
            }
        }

        public double Surface { get; set; }

        public override string ToString()
        {
            return string.Format("The surface of the trianlge is: {0}", this.Surface.ToString());
        }
    }
}